package com.ciaojian.client.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ciaojian.core.mapper.DyRecordMapper;
import com.ciaojian.core.model.DyRecord;
import com.ciaojian.core.service.DyRecordService;
import com.ciaojian.core.util.DateUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author oxiny
 */
@Service
public class DyRecordServiceImpl<M extends BaseMapper<T>, T> extends DyRecordService<DyRecordMapper, DyRecord> {

    /**
     * 获取用户今天购买的抖音产品记录
     *
     * @param userId 用户ID
     * @return 抖音产品记录
     */
    public DyRecord getByUserToday(Integer userId) {
        return this.lambdaQuery()
                .eq(DyRecord::getUserId, userId)
                .eq(DyRecord::getUsed, Boolean.FALSE)
                .between(DyRecord::getCreateTime, DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
                .last("limit 1")
                .one();
    }

}
